<template>
  <view>
    <u-navbar title="体重记录" back-icon-size="34" title-size="36" :border-bottom="false" :background="background" title-color="#222" back-icon-color="#222"></u-navbar>
    <view class="" style="margin-top: 20rpx; background: #fff">
      <view class="" style="display: flex; align-items: center; justify-content: space-between; height: 99rpx; border-bottom: 1rpx solid #e7e7e7">
        <view class="" style="font-size: 28rpx; padding-left: 29rpx">您的体重</view>
        <view class="" style="display: flex; align-items: center; padding-right: 35rpx">
          <input type="text" placeholder="请输入体重" style="font-size: 26rpx; color: #999999; width: 130rpx" v-model="weight" @blur="blur" />
          <text style="font-size: 28rpx; padding-left: 26rpx">kg</text>
        </view>
      </view>
      <view class="" style="display: flex; align-items: center; justify-content: space-between; height: 99rpx">
        <view class="" style="font-size: 28rpx; padding-left: 29rpx">您的身高</view>
        <view class="" style="display: flex; align-items: center; padding-right: 35rpx">
          <input type="text" placeholder="请输入身高" style="font-size: 26rpx; color: #999999; width: 130rpx" v-model="height" @blur="blur" />
          <text style="font-size: 28rpx; padding-left: 26rpx">cm</text>
        </view>
      </view>
    </view>
    <!-- BMI -->
    <view class="" style="margin-top: 20rpx; background: #fff">
      <view class="" style="display: flex; align-items: center; justify-content: space-between; height: 99rpx; border-bottom: 1rpx solid #e7e7e7">
        <view class="" style="font-size: 28rpx; padding-left: 29rpx">BMI</view>
        <view class="" style="font-size: 28rpx; color: #666666; padding-right: 35rpx">
          {{ bmi }}
        </view>
      </view>
      <view class="" style="display: flex; align-items: center; justify-content: space-between; height: 99rpx; border-bottom: 1rpx solid #e7e7e7" @tap="show = true">
        <view class="" style="font-size: 28rpx; padding-left: 29rpx">测量日期</view>
        <view class="" style="padding-right: 35rpx">
          <u-icon name="arrow-right" color="#666666" size="28" :label="time" label-pos="left"></u-icon>
        </view>
      </view>
      <!-- <view class="" style="display: flex;align-items: center;justify-content: space-between;height: 99rpx;" @tap="show1=true">
				<view class="" style="font-size: 28rpx;padding-left: 29rpx;">
					测量时间
				</view>
				<view class="" style="padding-right: 35rpx;">
					<u-icon name="arrow-right" color="#666666" size="28" :label="times" label-pos="left"></u-icon>
				</view>
			</view> -->
    </view>
    <view class="" style="position: absolute; width: 100%; bottom: 0">
      <view class="btn" @tap="sub">提交数据</view>
    </view>
    <u-picker mode="time" v-model="show" :params="params" @confirm="confirm"></u-picker>
    <u-picker mode="time" v-model="show1" :params="param" @confirm="confirm1"></u-picker>
  </view>
</template>

<script>
export default {
  data() {
    return {
      background: {
        background: '#FFFFFF'
      },
      weight: '',
      height: '',
      bmi: 0,
      params: {
        year: true,
        month: true,
        day: true,
        hour: true,
        minute: true,
        second: false
      },
      show: false,
      show1: false,
      param: {
        year: false,
        month: false,
        day: false,
        hour: true,
        minute: true,
        second: false
      },
      time: '',
      times: ''
    };
  },
  methods: {
    blur() {
      if (this.weight != '' && this.height != '') {
        let num = Number(this.height / 100);
        let ss = Number(num * num);
        this.bmi = (this.weight / ss).toFixed(2);
      }
    },
    confirm(e) {
      console.log(e);
      this.time = e.year + '-' + e.month + '-' + e.day + ' ' + e.hour + ':' + e.minute;
    },
    confirm1(e) {
      this.times = e.hour + ':' + e.minute;
    },
    sub() {
      if (this.weight == '') {
        uni.showToast({
          title: '请输入您的体重',
          icon: 'none'
        });
      } else if (this.height == '') {
        uni.showToast({
          title: '请输入您的身高',
          icon: 'none'
        });
      } else if (this.time == '') {
        uni.showToast({
          title: '请选择您的测量日期',
          icon: 'none'
        });
      } else {
        this.api({
          url: '/api/healthy/addDataOne',
          method: 'post',
          data: {
            value_one: this.height,
            value_two: this.weight,
            value_three: this.bmi,
            measure_time: this.time
          }
        }).then((res) => {
          uni.showToast({
            title: res.msg,
            icon: 'none'
          });
          setTimeout(() => {
            uni.navigateBack();
          }, 1500);
        });
      }
    }
  }
};
</script>

<style>
page {
  background: #f8f8f8;
}

.btn {
  margin: 99rpx 115rpx;
  height: 80rpx;
  background: linear-gradient(180deg, #1a9eff, #0fb8ff);
  border-radius: 40rpx;
  font-size: 32rpx;
  color: #fff;
  text-align: center;
  line-height: 80rpx;
}
</style>
